/** \file Envelope_t.cc 
 * Test definitions for the Envelope function.
 *
 * (C) Copyright by Semih Cemiloglu
 * All rights reserved, see COPYRIGHT file for details.
 *
 * $Id: Envelope_t.cc 110 2006-06-19 03:38:33Z semihc $
 *
 *
 */


#include "Envelope.hpp"
#include <vector>
#include "MASimple.hpp"
#include "TestHarness.hh"

using namespace std;
using namespace TC;


namespace {

  const unsigned DataSize = 56;

  const double data_cls[DataSize] = {
    18.5938, 18.6562, 18.5625, 19.5625, 19.1875, 19.9688, 21.4062,
    20.7812, 20.8125, 19.8125, 20.0938, 19.5312, 19.8750, 18.9688,
    18.8438, 19.7500, 18.8750, 18.8750, 19.0000, 18.9688, 19.3125,
    19.2188, 19.5625, 19.0625, 19.5625, 19.1250, 18.9062, 18.8750,
    18.7812, 17.8750, 17.4688, 17.3750, 17.5938, 18.3750, 18.8125,
    18.1562, 18.0000, 18.7188, 18.9688, 19.0000, 18.7188, 18.3125,
    18.2812, 18.0312, 17.5938, 16.8438, 16.2500, 16.2188, 17.0938,
    16.9688, 17.0000, 16.3125, 16.8125, 17.4062, 17.8750, 18.0625 };

  const double expect_elo[DataSize] = {
    0, 0, 0, 0,
    18.3451, 18.6119, 19.1454, 19.5758, 19.8183, 19.9396, 19.9638,
    19.6001, 19.4243, 19.0666, 18.8786, 18.8119, 18.6846, 18.4906,
    18.4967, 18.5209, 18.4361, 18.5028, 18.6361, 18.6483, 18.7634,
    18.7271, 18.6664, 18.5331, 18.4785, 18.1511, 17.8298, 17.5328,
    17.2842, 17.2054, 17.3873, 17.5206, 17.6419, 17.8601, 17.9753,
    18.0117, 18.1208, 18.1815, 18.0966, 17.9147, 17.6419, 17.2781,
    16.8780, 16.4779, 16.2960, 16.1748, 16.2051, 16.2172, 16.3324,
    16.3930, 16.5688, 16.7749 };

  const double expect_ehi[DataSize] = {
    0, 0, 0, 0,
    19.4799, 19.7631, 20.3296, 20.7867, 21.0442, 21.1729, 21.1987,
    20.8124, 20.6258, 20.2459, 20.0464, 19.9756, 19.8404, 19.6344,
    19.6408, 19.6666, 19.5764, 19.6473, 19.7889, 19.8018, 19.9241,
    19.8854, 19.8211, 19.6794, 19.6215, 19.2739, 18.9327, 18.6173,
    18.3533, 18.2696, 18.4628, 18.6044, 18.7331, 18.9649, 19.0872,
    19.1258, 19.2417, 19.3061, 19.2159, 19.0228, 18.7331, 18.3469,
    17.9220, 17.4971, 17.3040, 17.1753, 17.2075, 17.2203, 17.3426,
    17.4070, 17.5937, 17.8126 };


}

TEST(EnvelopeTest, Base)
{
     vector<TAfp_t> sma;
     vector<TAfp_t> envlo, envhi;

     // 3% Envelope of simple moving average of 5-period
     MASimple(data_cls, data_cls+DataSize,
	      back_inserter(sma),
	      5, // 5 period
	      ArrayAdaptor<double>());

     Envelope(sma.begin(), sma.end(),
	      back_inserter(envlo),
	      back_inserter(envhi),
	      0.03, // 3 percent
	      ArrayAdaptor<TAfp_t>());

     TC_TEST(envlo.size()==DataSize);
     TC_TEST(envhi.size()==DataSize);

     PrintElements(envlo, "Envelope-low");
     PrintElements(envhi, "Envelope-high");

     unsigned i;

     for(i=0; i<DataSize; ++i)
       if(expect_elo[i] > 0)
         TC_TESTFP(expect_elo[i], envlo[i]);

     for(i=0; i<DataSize; ++i)
       if(expect_ehi[i] > 0)
         TC_TESTFP(expect_ehi[i], envhi[i]);

}

  


